package com.qj.yantaishan.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.domain.CateGory;
import com.qj.yantaishan.service.CateGoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/yantaishan")
public class CateGoryController extends BaseController {
//    private String all="yantaishan/catenews";
    @Autowired
    private CateGoryService cateGoryService;

    /**
     * @查询所有新闻分类--分页
     * */
    @GetMapping("/StoreNewsCategory/map")
    public String list01(Integer currentPage, Integer pageSize)
    {
//        QueryWrapper<CateGory> wrapper=new QueryWrapper<>();
        Page<CateGory> page = new Page<>(currentPage,pageSize);
        Page<CateGory> CateGoryPage =cateGoryService.page(page);
        return JSON.toJSONString(CateGoryPage);
    }
    /**
     * @根据id查询新闻分类
     * */
    @RequestMapping("/StoreNewsCategory/typeId")
    public List<CateGory> list02(Integer id)
    {
        List<CateGory> list=cateGoryService.selectCateGoryId(id);
        return list;
    }
    @PutMapping("StoreNewsCategory/{id}")
    public int updateNews(@PathVariable("id") Integer id, @PathVariable("storeId") Integer storeId, @PathVariable("name") String name, @PathVariable("sort") String sort, @PathVariable("addTime") Integer addTime){
        CateGory cateGory=new CateGory(id,storeId,name,sort,addTime);
        System.out.println(cateGory);
        return cateGoryService.updateNews(cateGory);
    }
}
